﻿//Write a program that, for a given two integer numbers N and X, calculates the sumS = 1 + 1!/X + 2!/X^2 + … + N!/X^N
//1+1!/6 + 2!/6^2 + 3!/6^3 + 4!/6^4

using System;
using System.Numerics;

class SumOfFactDivByXSeries
{
    static void Main()
    {
        Console.Write("Enter X = ");
        decimal x = decimal.Parse(Console.ReadLine());
        Console.Write("Enter N = ");
        decimal n = decimal.Parse(Console.ReadLine());

        decimal result = 1;
        decimal factorialN = 1;
        decimal xPowN = 1;
        for (int i = 1; i <= n; i++)
        {
            factorialN = factorialN * i;
            xPowN = xPowN * x;
            result = result + factorialN / xPowN;
        }
        Console.WriteLine("S = 1 + 1!/{0} + 2!/{0}^2 + ... + {1}!/{0}^{1} = {2}", x, n, result);
    }
}
